// index.js
// 获取应用实例
const { loginWechat} = require('../../http/api')


Page({
  data: {

  },
  onLoad() {},
  GetUserInfo(e) {
    var _this = this
    wx.login({
      success: (res) => {
        const code = res.code
        const encryptedData = e.detail.encryptedData
        const iv = e.detail.iv
        const signature = e.detail.signature
        const rawData = e.detail.rawData
        var obj = {
          code:code,
          encryptedData: encryptedData,
          iv: iv,
          signature: signature,
          rawData: rawData
        }
        // console.log(obj)
        loginWechat(obj).then(res=>{
          if(res.code == 200){
            wx.showToast({
              title: '授权成功',
            })
            const token = res.token
            wx.setStorageSync("token",{data:token})
            wx.switchTab({
              url: '../index/index',
            })
          }else{
            wx.showToast({
              title: '授权失败',
            })
          }
         
        })
      }
    })

  },
})